<template>
  <div class="app">
       <!-- navbar组件 -->
       <van-nav-bar
      title="搜索"
      left-text="返回"
      right-text="..."
      left-arrow
      @click-left="onClickLeft"
    />
    <!-- 搜索框 -->
    <div class="inputBox">
            <input type="text" placeholder="搜索商家，商品名称" v-model="searchText">
            <div @click="search">搜索</div>
     </div>
     <!-- 渲染搜索列表 -->
     <div class="homeList">
        <div class="list">
            <div class="box" v-for="(item,index) in shop_list" :key="index" @click="toTetail(item)">
                <img :src="item.picUrl" alt="">
                <div class="text">
                    <h4>{{item.name}}</h4>
                    <div class="tet">
                         <p><span>☆4.3</span> <span>{{item.monthSalesTip}}</span></p>
                    </div>
                   
                    <div class="txt">
                        <p><span>{{item.minPriceTip}}</span><span>{{item.shippingFeeTip}}</span></p>
                        <p><span>{{item.deliveryTimeTip}}</span><span>{{item.distance}}</span></p>
                    </div>
                    
                </div>
            </div>
        </div>
    </div>
    <div class="empty" v-show="shop_list.length==0">
        <p> <span>暂未筛选到任何商品</span><span>为您推荐以下商品</span> </p>
    </div>
    <HomeListVue v-show="shop_list.length==0"></HomeListVue>
  </div>
</template>

<script>
import HomeListVue from '@/components/HomeList.vue';
import {shop_search} from '../utils/api'
export default {
    data(){
        return{
            shop_list:[],
            searchText:''
        }
    },
    components:{
        HomeListVue
    },
    mounted(){
        this.searchText =this.$route.params.key;
        let searchkey=this.searchText
        shop_search({searchkey}).then((res)=>{
                if(res.data.list){
                   this.shop_list=res.data.list
                   console.log(res.data.list)
                }
            })
    },
    methods:{
        onClickLeft(){
            this.$router.go(-1)
        },
        search(){
            let searchkey=this.searchText
            shop_search({searchkey}).then((res)=>{
                if(res.data.code==200){
                   this.shop_list=res.data.list
                   console.log(res.data.list)
                }
            })
        },
        toTetail(item){
            console.log(item)
            this.$router.push('/detail/'+item.mtWmPoiId)
        }
    }
    
}
</script>

<style lang="scss" scoped>
.app{
    width: 100%;
    box-sizing: border-box;
    padding: 10px;
}
.inputBox {
    width: 100%;
    display: flex;
    margin: 20px 0;
}

.inputBox input {
    flex: 1;
    height: 40px;
    border: none;
    outline: none;
    border-radius: 20px;
    background-color: rgb(241, 241, 241);
    padding-left: 20px;
}

.inputBox div {
    width: 60px;
    height: 40px;
    text-align: center;
    line-height: 40px;
    color: rgb(95, 195, 235);
    font-size: 18px;
}

.box{
    display: flex;
    padding: 0 10px;
    margin-top: 10px;
    img{
        width: 90px;
        height: 90px;
        margin-right: 10px;
    }
    .text{
        width: 100%;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        .txt{
        display: flex;
        justify-content:space-between;
        color: gray;
        font-size: 14px;
    }
        .tet p span:first-child{
            color: orangered;
        }
    }  
}
.empty{
    padding: 20px;
    box-sizing: border-box;
    height: 100px;
    line-height: 100px;
    text-align: center;
      p span:first-child{
        font-size: 20px;
     }
}

</style>